package com.thunisoft.audio.Controller;

import com.thunisoft.audio.Service.FileTransAli;
import com.thunisoft.audio.Service.FileTransKaldi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.sql.PreparedStatement;

@Controller
public class CommonController {

    @Autowired
    private FileTransAli fileTransAli;

    @Autowired
    private FileTransKaldi fileTransKaldi;

    @RequestMapping(value = "/")
    public String webPlatformIndex() {
        return "index";
    }

    @RequestMapping("/aliSubmit")
    @ResponseBody
    public String fileTransRequest(@RequestParam("file")MultipartFile file) {
        String result = null;
        try {
            String taskId = fileTransAli.submitFileTrans(file);
            result = fileTransAli.getFileTransResult(taskId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/KaldiSubmit")
    @ResponseBody
    public String fileTransKaldiRequest(@RequestParam("file")MultipartFile file) {
        String result = null;
        try {
            result = fileTransKaldi.getFileTransResult(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
